package uit.nfcmenu.waiter.controllers;

import java.util.ArrayList;
import java.util.Hashtable;

import android.content.Context;

import uit.nfcmenu.models.DatabaseManager;
import uit.nfcmenu.models.IDataChangeHandler;
import uit.nfcmenu.models.ItemModel;
import uit.nfcmenu.models.OrderModel;
import uit.nfcmenu.utils.CommConstant;
import uit.nfcmenu.utils.CommUrl;
import uit.nfcmenu.utils.WebserviceHelper;

public class DatabaseManagerChef extends DatabaseManager {
	public static final String tag = DatabaseManagerChef.class.getSimpleName();

	// ===========================================
	// Fields
	// ===========================================
	static IDataChangeHandler mObjDataWillChanged;
	static DatabaseManagerChef mInstance;

	// ===========================================
	// Constructors, System Methods, Event Methods
	// ===========================================
	public DatabaseManagerChef(Context context) {
		super(context);		
	}

	public static DatabaseManagerChef getInstance(IDataChangeHandler context) {
		mObjDataWillChanged = context;
		if (mInstance == null) {
			mInstance = new DatabaseManagerChef(
					mObjDataWillChanged.getContext());
			mID = 0;
		}

		return mInstance;
	}

	// -------------------------------------------
	// Controls Getting Data in background
	// -------------------------------------------

	// -------------------------------------------
	// Controls Network
	// -------------------------------------------

	// -------------------------------------------
	// Controls data
	// -------------------------------------------

	// -------------------------------------------
	// Controls Database
	// -------------------------------------------

	/*
	 * Controls Database Menu
	 */

	public ArrayList<ItemModel> getAllItem() {
		ArrayList<ItemModel> arrayItem = super.getAllItemsInDB();
		CommConstant.item = new Hashtable<Integer, String>();

		for (int i = 0; i < arrayItem.size(); i++) {
			CommConstant.item.put(arrayItem.get(i).getItemID(), arrayItem
					.get(i).getItemName());
		}
		return arrayItem;
	}

	public boolean editStatus(int orderID, String status, String comment) {
		String url = CommUrl.createUrlChangeOrderStatus(orderID, status,
				comment);
		String respone = WebserviceHelper.callWS(url);
		if (CommConstant.GET_DATA_SUCCESS.equals(respone)) {
			OrderModel model = new OrderModel();
			model.setOrderID(orderID);
			model.setStatus(status);
			model.setComment(comment);
			mOrderAdapter.updateOrderModel(model);
			return true;
		} else {
			return false;
		}
	}
}
